microbit = codesters.Microbit()
microbit.show_string("hello")
stage.set_background("moon")
sprite = codesters.Sprite("astronaut1")
sprite.move_down(150)
def button_a():
sprite.move_left(50)
microbit.event_button_a(button_a)
def button_b():
sprite.move_right(50)
microbit.event_button_b(button_b)
ball = codesters.Sprite("rock")
ball.set_x_speed(5)
ball.set_y_speed(5)
def collision(sprite, hit_sprite):
hit_sprite.set_y_speed(5)
sprite.event_collision(collision)
stage.disable_floor()
t = codesters.Teacher()
try:
set_y_speeds = t.find_function("set_y_speed")
tval1 = set_y_speeds[1][1]
except:
tval1 = "DNE"
try:
get_y_speeds = t.find_function("get_y_speed")
tval2 = get_y_speeds[0][1]
except:
tval2 = "DNE"
try:
tval3 = get_y_speeds[0][1]
except:
tval3 = "DNE"
try:
tval4 = t.get_indent_at_line(get_y_speeds[0][0])
except:
tval4 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == "DNE", "Great job!")
t1.add_failure(tval1 != "DNE", "Did you delete the set_y_speed() command in your collision event?")
t2 = TestObjective()
t2.add_success(tval2 != "DNE", "Great job!")
t2.add_failure(tval2 == "DNE", "Did you add a Get y Speed command?")
t3 = TestObjective()
t3.add_success("hit_sprite.get_y_speed" in tval3, "Great job!")
t3.add_failure("hit_sprite.get_y_speed" not in tval3, "Did you change the name in front of get_y_speed from sprite to hit_sprite?")
t3.add_failure(tval3 == "DNE", "Did you add in the Get y Speed command?")
t4 = TestObjective()
t4.add_success(tval4 == 4, "Great job!")
t4.add_failure(tval4 == 0, "Make sure get_y_speed is indented inside the collision event!")
t4.add_failure(tval4 < 4 or tval4 > 4, "Did you indent get_y_speed exactly 4 spaces or 1 tab?")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)